package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.domain.Picture;
import com.example.demo.service.PictureService;
import com.example.demo.service.PictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Create:     LT4
 * @Time:       2020年6月1日21:41:06
 * @Describe:   用于查询Picture物流快递信息
 *  8 超时单 9 签收失败 10 退回
 */
@Controller
@RequestMapping("/picture")
public class PictureController {

    @Autowired
    private PictureService pictureService;


    @ResponseBody
    @GetMapping("/get/{id}")
    public Picture getPictureById(@PathVariable("id") Integer id){
        return pictureService.getPictureById(id);
    }


    @ResponseBody
    @GetMapping("/get/{gid}")
    public List<Picture> getPictureListByGidd(@PathVariable("gid") Integer gid){
        return pictureService.getPictureListByGid(gid);
    }

    /**
     * @Modify:     Space
     * @Time:       2020-6-17 00:00:16
     */
//    @ResponseBody
//    @DeleteMapping("del/{id}")
//    public String delPictureById(@PathVariable("id") Integer id){
//        pictureService.delPictureById(id);
//        return "del Picture success";
//    }
    @PostMapping("del/{id}")
    public String delPictureById(@PathVariable("id") Integer id,@RequestParam(value = "url",required = false)String url){
        pictureService.delPictureById(id);
        return "redirect:"+url;
    }

    @ResponseBody
    @PostMapping("/add")
    public String getPictureById(@RequestBody Picture Picture){
        pictureService.addPicture(Picture);
        return "add Picture success";
    }

    @ResponseBody
    @PutMapping("/save/")
    public String savePicture(@RequestBody Picture Picture){
        pictureService.savePicture(Picture);
        return "save Picture success";
    }



}
